package com.hadoop.mapreduce.mobilestatistics;

import com.hadoop.mapreduce.mobilestatistics.bean.MobileStatisticalData;
import com.hadoop.mapreduce.mobilestatistics.bean.MobileTrafficInformation;
import com.hadoop.mapreduce.mobilestatistics.map.MobileMap;
import com.hadoop.mapreduce.mobilestatistics.reduce.MobileReduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author chenxigu
 */
public class MobileFlowCount {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        /**
         *  hdfs://emr-header-1.cluster-285604:9000/user/student5/input/HTTP_20130313143750.dat
         *  hdfs://emr-header-1.cluster-285604:9000/user/student5/user/student5/chenxi.gu/result
         */
        args = new String[]{
                "hdfs://emr-header-1.cluster-285604:9000/user/student5/input/HTTP_20130313143750.dat",
                "hdfs://emr-header-1.cluster-285604:9000/user/student5/chenxi/result"
        };
//        args = new String[]{
//                "./src/main/resources/HTTP_20130313143750.dat", "./src/main/resources/result"
//        };
        Job job = Job.getInstance(new Configuration());
        job.setJarByClass(MobileFlowCount.class);
        job.setMapperClass(MobileMap.class);
        job.setReducerClass(MobileReduce.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(MobileTrafficInformation.class);

        job.setOutputKeyClass(MobileStatisticalData.class);
        job.setOutputValueClass(Text.class);

        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        job.waitForCompletion(true);
    }
}
